package com.cctc.framework.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

import com.cctc.framework.util.DateUtil;

public class DatetimeBoxTag extends TagSupport {

	private static final long serialVersionUID = 1971120936516947979L;

	private String id;

	private String style;

	private String value;

	@Override
	public int doEndTag() throws JspException {
		try {
			renderPaginator();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public void renderPaginator() throws IOException {
		JspWriter out = this.pageContext.getOut();
		out.write("<input id=\"");
		out.write(this.getId());
		out.write("\" class=\"easyui-datetimebox\" name=\"birthday\" data-options=\"required:true\"  type=\"text\"");
		if (getStyle() != null && "" != style) {
			out.write("style=\"");
			out.write(getStyle());
			out.write("\"");
		}
		if (getValue() != null && "" != value) {
			out.write("value=\"");
			out.write(getValue());
			out.write("\"");
		} else {
			out.write("value=\"");
			out.write(DateUtil.getNow());
			out.write("\"");
		}
		out.write("\">");
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		try {
			this.id = (String) ExpressionEvaluatorManager.evaluate("id", id,
					Object.class, this, pageContext);
		} catch (JspException e) {
			e.printStackTrace();
		}
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		try {
			this.style = (String) ExpressionEvaluatorManager.evaluate("style",
					style, Object.class, this, pageContext);
		} catch (JspException e) {
			e.printStackTrace();
		}
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		try {
			this.value = (String) ExpressionEvaluatorManager.evaluate("value",
					value, Object.class, this, pageContext);
		} catch (JspException e) {
			e.printStackTrace();
		}
	}

}
